import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'
import {AtTabs,AtTabsPane,AtInput,AtButton} from 'taro-ui'
import './tianjiahuanzhe.scss'
import reactMixin from 'react-mixin';
import myJs from './tianjiahuanzheJs.js'
import app from '../../../../main.js'

export default class Tianjiahuanzhe extends Component {
    config = {
        navigationBarTitleText: '添加患者'
    }
    constructor () { 
        super(...arguments); 
        this.state = this.getData(); 
    }
    // constructor () {
    //     super(...arguments)
    //     this.state = {
    //       current: 0,
    //     }
    //   }
    //   handleClick (value) {
    //     this.setState({
    //       current: value
    //     })
    //   }
    init(){
        this.setState({
            name:'',
            phone_number:'',
            current:0,
        })
        this.getDoctor();
        this.getQrcode();
        this.getSend();
    }
    afterGetDoctor(){
        this.setState({
            doctor:this.state.doctor
        });
    }
    afterGetSend(data){
        data.id=app.current.id;
        data.name=this.setState.name;
        data.phone_number=this.setState.phone_number;
        if(data.name===''||data.name===null||Number.parseInt(data.name)===0){
            app.alertTab('请输入患者姓名');
            return false;
        }
        if(data.phone_number===''||data.phone_number===null||Number.parseInt(data.phone_number)===0){
            app.alertTab('请输入患者姓名');
            return false;
        }
        this.setState({
            send:this.state.send
      });
        return true;
    }
    downloadFile(){
        url= this.state.qrcode.head_image, 
        success=(res)=> {
          // 只要服务器有响应数据，就会把响应内容写入文件并进入 success 回调，业务需要自行判断是否下载到了想要的内容
          if (res.statusCode === 200) {
            wx.playVoice({
              filePath: res.tempFilePath
            })
          }
        }
      }
    updateShareMenu(){
        withShareTicket=true,
        success=()=> {this.state.qrcode.head_image }
      }

    render () {
        return (
            <View className='tianjiahuanzhe'>
                <AtTabs 
                 current={this.state.current} 
                 onClick={this.handleChange.bind(this,'current')} 
                 tabList={[{title:'手机号码添加'},{title:'二维码添加'}]}>
                    <AtTabsPane current={this.state.current} index={0}>
                        <View className=' class_0'>
                            <Text className=' class_1'>患者信息</Text>
                        </View>
                        <AtInput 
                         placeholder='请输入患者姓名' 
                         border={false} 
                         className=' class_2'
                         value={this.state.name}
                         onChange={this.handleChange.bind(this,'name')}
                         ></AtInput>
                        <AtInput 
                         placeholder='请输入手机号码' 
                         border={false}
                         value={this.state.phone_number}
                         onChange={this.handleChange.bind(this,'phone_number')}
                         ></AtInput>
                        <View className=' class_3'>
                            <Text className=' class_4'>短信发送模板</Text>
                        </View>
                        <View className=' class_5'>
                            <Text className=' class_6'>{this.setState.name}您好，我是{this.state.doctor.name}医生，有任何关于你病情相关的问题想咨询我，请通过微信扫描链接 <Text className='t'>http://xajkfjiekf/rf/fdfadf</Text>中二维码来联系我。</Text>
                        </View>
                        <View className=' class_7'></View>
                        <AtButton className=' class_8' full>
                            <Text className=' class_9'>发送邀请</Text>
                        </AtButton>
                    </AtTabsPane>
                    <AtTabsPane current={this.state.current} index={1}>
                        <View className=' class_10'>
                            <View className=' class_11'>
                                <Text className=' class_12'>微信扫一扫关注{this.state.doctor.name}医生</Text>
                            </View>
                            <View className=' class_13'>
                                <Text className=' class_14'>随时随地都能问医生</Text>
                            </View>
                            <Image className=' class_15' src={this.state.qrcode.head_image}></Image>
                            <View className=' class_16'>
                                <Text className=' class_17'>{this.state.doctor.name}</Text>
                            </View>
                            <View className=' class_18'>
                                <Text className=' class_19'>{this.state.doctor.positional_title} | 综合{this.state.doctor.department}</Text>
                            </View>
                            <View className=' class_20'>
                                <Text className=' class_21'>{this.state.doctor.hospital}</Text>
                            </View>
                        </View>
                        <View className='at-row btn-box'>
                            <View className='at-col at-col-6'>
                                <AtButton type='primary' full={true} className='cancel-btn'>保存名片</AtButton> 
                            </View>
                            <View className='at-col at-col-6'>
                                <AtButton type='primary' full={true} className='update-btn'>分享名片</AtButton> 
                            </View>
                        </View>
                        {/* <View className=' class_22'>
                            <View className=' class_23'>
                                <AtButton className=' class_24' onClick={this.downloadFile}>
                                    <Text className='white-text' >下载名片</Text>
                                </AtButton>
                            </View>
                            <View className=' class_25'>
                                <AtButton className=' class_26' onClick={this.updateShareMenu}>
                                    <Text className='white-text'>分享名片</Text>
                                </AtButton>
                            </View>
                        </View> */}
                    </AtTabsPane>
                </AtTabs>
            </View>
        );
    }
}
reactMixin.onClass(Tianjiahuanzhe,myJs);